#!/usr/bin/ruby
require 'rubygems'
require 'mechanize'
require 'date'
require 'net/smtp'
require 'base64'
require 'fanmairenkou'

begin
	$agent = WWW::Mechanize.new
	$agent.user_agent_alias = "Windows IE 6"
	puts "[程序]: <#{Time.now()}> 正在登录校內..."
	page = $agent.get("http://www.xiaonei.com")
	search_form = page.forms.first
	search_form.fields.name("email").value = ARGV[0] 
	search_form.fields.name("password").value = ARGV[1]
	$agent.submit(search_form)
	$agent.get("http://friendsell.xiaonei.com/friendsell/card.do")
	0.upto(100) do |i|
		$agent.post("http://friendsell.xiaonei.com/friendsell/buycard.do", {:cardCount => "3" , :cardid => "20" })
		$agent.post("http://friendsell.xiaonei.com/friendsell/buycard.do", {:cardCount => "3" , :cardid => "19" })
		$agent.post("http://friendsell.xiaonei.com/friendsell/buycard.do", {:cardCount => "3" , :cardid => "23" })
	end
#		page2 = $agent.post("http://friendsell.xiaonei.com/friendsell/buycard.do", {:cardCount => "3" , :cardid => "23" })
#	page2 = $agent.post("http://friendsell.xiaonei.com/friendsell/buycard.do", {:cardCount => "500" , :cardid => "20" })
#	page2 = $agent.post("http://friendsell.xiaonei.com/friendsell/buycard.do", {:cardCount => "500" , :cardid => "22" })
#	page2 = $agent.post("http://friendsell.xiaonei.com/friendsell/buycard.do", {:cardCount => "500" , :cardid => "29" })
rescue Exception => e
	puts "#{e}\n"
end
